package com.kmvc.message.activity;

import java.util.ArrayList;

import com.kmvc.message.R;
import com.kmvc.message.service.MessageService;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class Message extends Activity implements OnClickListener {
	 
	private Button close;
	protected static final int RESULT_SPEECH = 1;
	private MessageApplication application=null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// 
		super.requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.messagedetail);
		application=(MessageApplication)getApplication();
		Intent intents = new Intent(
				RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
		intents.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
		try {
			startActivityForResult(intents, RESULT_SPEECH);
			//txtText.setText("");
		} catch (ActivityNotFoundException a) {
			Toast t = Toast.makeText(this,
					"Ops! Your device doesn't support Speech to Text",
					Toast.LENGTH_SHORT);
			t.show();
		}
		close=(Button)findViewById(R.id.close);
		close.setText("信息通报有新消息,点击查看详情");
		close.setOnClickListener(this);
		 
		try {
			//getXML(message);
		} catch (Exception e) {
			//  
			e.printStackTrace();
		}
		
	}


	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		switch (requestCode) {
		case RESULT_SPEECH: {
			if (resultCode == Activity.RESULT_OK && null != data) {

				ArrayList<String> text = data
						.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
				application.result=text.get(0);
				//txtText.setText(text.get(0));
			}
			break;
		}

		}
	}

	@Override
	public void onClick(View v) {
		//
		try{
//		MessageService service = new MessageService();
		MessageService.manager.cancel(0);}
		catch(Exception e)
		{
			Log.e("Message",e.toString());
		}
		Intent intent = new Intent(this,LoginActivity.class);
		this.startActivity(intent);
		this.finish();
	}
}
